<template>
  <div>
    <van-nav-bar fixed title="业绩考核" left-arrow class="color-white bg-primary" @click-left="back()" />
    <div class="has-top pos-r ">
      <div class="wrappertop">
        <div class="selectmain bg-primary">
          <div class="tip"><span>当前等级</span><span class="two">降级等级</span></div>
          <div class="agency">
            <div class="agency_left color-primary text-show-line-1">{{presentGrade}}</div>
            <div class="agency_center">
              <div>降级为</div>
              <span></span>
            </div>
            <div class="agency_right" @click="agencySelect()">
              <div class="text-show-line-1">{{futureGrade}}</div>
              <van-icon :name="Icon" size="12" />
            </div>
          </div>
        </div>
        <div class="topmain">
          <span>剩余天数</span>
          <div><strong>{{gradeInfoData.DiffDays}}</strong><span>天</span></div>
        </div>
      </div>
      <ul class="listmain">
        <li>
          <div class="listleft">
            <span>个</span>
            <span>人</span>
            <span>业</span>
            <span>绩</span>
          </div>
          <div class="listright">
            <div class="r-top">
              <div ><strong>{{GradeData.UserAmount}}</strong><span>元</span></div>
              <span class="name">个人目标业绩</span>
            </div>
            <div class="r-bottom">
              <div class="r-top">
                <div ><strong>{{gradeInfoData.UserAmount}}</strong><span>元</span></div>
                <span class="name">已完成</span>
              </div>
              <div class="r-top r-last">
                <div ><strong>{{(gradeInfoData.UserAmount/GradeData.UserAmount)*100}}</strong><span>%</span></div>
                <span class="name">已完率</span>
              </div>
            </div>
          </div>
        </li>
        <li>
          <div class="listleft">
            <span>团</span>
            <span>队</span>
            <span>业</span>
            <span>绩</span>
          </div>
          <div class="listright">
            <div class="r-top">
              <div ><strong>{{GradeData.TeamAmount}}</strong><span>元</span></div>
              <span class="name">团队目标业绩</span>
            </div>
            <div class="r-bottom">
              <div class="r-top">
                <div ><strong>{{gradeInfoData.TeamAmount}}</strong><span>元</span></div>
                <span class="name">已完成</span>
              </div>
              <div class="r-top r-last">
                <div ><strong>{{(gradeInfoData.TeamAmount/GradeData.TeamAmount)*100}}</strong><span>%</span></div>
                <span class="name">已完率</span>
              </div>
            </div>
          </div>
        </li>
        <li>
          <div class="listleft">
            <span>团</span>
            <span>队</span>
            <span>人</span>
            <span>数</span>
          </div>
          <div class="listright">
            <div class="r-top">
              <div ><strong>{{GradeData.TeamNum}}</strong><span>人</span></div>
              <span class="name">目标团队人数</span>
            </div>
            <div class="r-bottom">
              <div class="r-top">
                <div ><strong>{{gradeInfoData.TeamNum}}</strong><span>人</span></div>
                <span class="name">已完成</span>
              </div>
              <div class="r-top r-last">
                <div ><strong>{{(gradeInfoData.TeamNum/GradeData.TeamNum)*100}}</strong><span>%</span></div>
                <span class="name">已完率</span>
              </div>
            </div>
          </div>
        </li>
        <li>
          <div class="listleft">
            <span>推</span>
            <span>荐</span>
            <span>等</span>
            <span>级</span>
          </div>
          <div class="listright">
            <div class="r-top">
              <div ><strong>{{GradeData.RecommendGradeNum}}</strong><span>VIP</span></div>
              <span class="name">目标推荐(等级)数量</span>
            </div>
            <div class="r-bottom">
              <div class="r-top">
                <div ><strong>{{gradeInfoData.RecommendGradeNum}}</strong><span>VIP</span></div>
                <span class="name">已完成</span>
              </div>
              <div class="r-top r-last">
                <div ><strong>{{(gradeInfoData.RecommendGradeNum/GradeData.RecommendGradeNum)*100}}</strong><span>%</span></div>
                <span class="name">已完率</span>
              </div>
            </div>
          </div>
        </li>
        <li>
          <div class="listleft">
            <span>团</span>
            <span>队</span>
            <span>数</span>
            <span>量</span>
          </div>
          <div class="listright">
            <div class="r-top">
              <div ><strong>{{GradeData.TeamGradeNum}}</strong><span>VIP及以上</span></div>
              <span class="name">目标团队(等级)数量</span>
            </div>
            <div class="r-bottom">
              <div class="r-top">
                <div ><strong>{{gradeInfoData.TeamGradeNum}}</strong><span>VIP及以上</span></div>
                <span class="name">已完成</span>
              </div>
              <div class="r-top r-last">
                <div ><strong>{{(gradeInfoData.TeamGradeNum/GradeData.TeamGradeNum)*100}}</strong><span>%</span></div>
                <span class="name">已完率</span>
              </div>
            </div>
          </div>
        </li>
      </ul>
        <!-- <no-data v-if="RewardList.length === 0" /> -->
        <van-popup v-model="startSelect" position="bottom">
          <van-picker
            show-toolbar
            :columns="columns"
            @confirm="onConfirm"
            @cancel="onCancel"
          />
        </van-popup>
    </div>
  </div>
</template>

<script>
import { Toast } from 'vant'
import datetimeSelect from 'components/datetimeSelect'
import noData from 'components/noData'
import { GetUserGradeDemotionSettingList,GetUserGradeDemotionData } from 'api/member'
import utils from 'utils/utils'
export default {
  components: {
    datetimeSelect,
    noData
  },
  data() {
    return {
      userId:0,
      columns: [],
      bgImg: require('assets/images/integrate.png'),
      startSelect: false,
      Icon: 'arrow-down',
      gradeList:[],
      presentGrade:'',
      futureGrade:'',
      gradeInfoData:{},
      GradeData:{},
      fromapp:0
    }
  },
  watch: {
    // dateSelect(newVal, oldVal) {
    //   if (newVal === true) {
    //     this.Icon = 'arrow-up'
    //   } else {
    //     this.Icon = 'arrow-down'
    //   }
    // }
  },
  created() {
    if(this.$route.query.userId){
      this.userId = this.$route.query.userId
    }
    if(this.$route.query.fromapp){
      this.fromapp = this.$route.query.fromapp
    }
    this.sttingList()
  },
  mounted() {

  },
  methods: {
    sttingList(){
      let path = '?userId='+this.userId
      GetUserGradeDemotionSettingList(path).then(res => {
        if (res.State==1) {
            this.gradeList = res.Data;
            this.presentGrade = res.Data[0].GradeName
            this.futureGrade = res.Data[0].DemotionGradeName
            this.futureID = res.Data[0].ID
            this.GradeData = res.Data[0]
            this.gradeList.forEach(e=>{
              this.columns.push(e.DemotionGradeName)
            })
            this.gradeInfo()
        }
      })
    },
    gradeInfo(){
      let path = '?userId='+this.userId+'&settingId='+this.futureID
      GetUserGradeDemotionData(path).then(res => {
        if (res.State==1) {
            this.gradeInfoData = res.Data;
        }
      })
    },
    agencySelect(){
      this.startSelect = true
    },
    back(){
      if(this.fromapp==1){
        uni.webView.navigateBack({  
        delta: 1,  
        })
      }else{
        this.$utils.back($route.path)
      }
    },
    onConfirm(value,index) {
      console.log(index)
      this.GradeData = this.gradeList[index]
      this.futureGrade = this.gradeList[index].DemotionGradeName
      this.futureID = this.gradeList[index].ID
      this.gradeInfo()
      // Toast(`当前值：${value}, 当前索引：${index}`);
      // this.GetUserWaitSettleReward()
      this.startSelect = false
    },
    onCancel(){
      this.startSelect = false
      
    },
    GetUserWaitSettleReward() {
      GetAccountData({startTime:this.requestData.StartTime,endTime:this.requestData.EndTime}).then(res => {
        if (res.State==1) {
          this.TotalMoney = res.Data
        }
      })
      let url;
      if(this.active==1){
        url= '/Order/GetAccountReceivableList'
      }else{
        url= '/Order/GetAccountPayableList'
      }
      GetAccountReceivableList(this.requestData,url).then(res => {
        if (res) {
          // this.TotalMoney = res.Data.TotalMoney
          if (res.Data.length && res.Data.length > 0) {
            res.Data.forEach(tem => {
              this.RewardList.push(tem)
            })
          }
           this.totalAmout = res.TotalAmout
          this.scollRequest = true
        }
      })
    },
    // // 滚动事件触发下拉加载
    // onScroll() {
    //   const _this = this
    //   if (_this.scollRequest === true) {
    //     if (utils.getScrollHeight() - utils.getClientHeight() - utils.getScrollTop() <= 5) {
    //       _this.scollRequest = false
    //       console.log('加载')
    //       if (_this.requestData.PageIndex < _this.totalAmout) {
    //         _this.requestData.PageIndex++
    //         _this.GetUserWaitSettleReward()
    //       } else {
    //         console.log('end')
    //         _this.end = true
    //       }
    //     }
    //   }
    // }
  }
}
</script>
<style lang="scss" scoped>
.body{
  background: red;
}
.color-white{
  /deep/.van-nav-bar__title,/deep/.van-icon{
    color:$colorF;
  }
}
/deep/.van-hairline--bottom::after{
  border-bottom: none;
}
.wrappertop{
  height: 506px;
  padding: 32px 32px 0 32px;
  background: #FFFFFF;
  box-shadow: 0px 12px 14px 0px rgba(0,0,0,0.05);
  border-radius: 0px 0px 24px 24px;
  margin-bottom: 32px;
  .selectmain{
    height: 238px;
    border-radius: 24px;
    .tip{
      font-size: 24px;
      color: #fff;
      padding-top: 48px;
      padding-left: 56px;
      padding-bottom: 20px;
      .two{
        padding-left: 275px;
      }
    }
  }
  .agency{
    padding: 0 32px;
    display: flex;
    justify-content: space-between;
    .agency_left,.agency_right{
      width: 252px;
      height: 88px;
      line-height: 88px;
      background: #FFFFFF;
      border-radius: 16px;
      font-size: 28px;
      font-weight: bold;
      text-align: center;

    }
    .agency_right{
      display: flex;
      justify-content: center;
      align-items: center;
      .text-show-line-1{
        width: 184px;

      }
    }
    .agency_center{
      height: 88px;
      display: flex;
      flex-direction: column;
      justify-content: center;
      align-items: center;
      div{
        width: 72px;
        height: 34px;
        font-size: 24px;
        font-weight: 400;
        color: #FFFFFF;
        line-height: 34px;
      }
      span{
        width: 71px;
        height: 5px;
        opacity: 0.8;
        border-bottom: 2px solid #FFFFFF;
      }
    }
  }
}
.topmain{
  padding: 42px 72px;
  & > span{
    font-size: 32px;
    color: #222A42;
    margin-bottom: 26px;
  }
  div{
    text-align: center;
    font-size: 38px;
      color: #222A42;
    strong{
      font-size: 96px;
      color: #222A42;
      padding-right: 12px;
    }
    span{
      font-size: 26rpx;
      vertical-align: 30px;
    }
  }
}
.right{
   display: flex;
  justify-content: flex-end;
.tbs{
  display: flex;
  border: 1px solid #fff;
  border-radius: 5px;
  div{
    height: 50px;
    width: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
  }
  .active{
    background: #fff;
  }

}
}
.line{
  padding: 5px;
  display: flex;
  justify-content: center;
  align-items: center;
  div{
    width: 15px;
    background: #fff;
    height: 3px;
  }
}
.color-ddd{
  color: #a8a8a8;

}
.main{
  background:#f3f4f6;
  height: 120px;
  display: flex;
  justify-content: space-around;
  &>div{
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
  }
  .color1{
    color: #53a24c;
  }
    .color2{
    color: #bb1718;
  }
    .color3{
    color: #298eed;
  }
}
.listmain{
  padding: 0 32px 32px 32px;
  li{
    height: 260px;
    display: flex;
    margin-bottom: 32px;
    .listleft{
      width: 56px;
      display: flex;
      flex-direction: column;
      margin-top: 28px;
      height: 204px;
      background: linear-gradient(132deg, #F49C36 0%, #FF8251 100%);
      border-radius: 16px 0px 0px 16px;
      color: #fff;
      font-size: 32px;
      justify-content: center;
      align-items: center;
    }
    .listright{
      height: 260px;
      background: #FFFFFF;
      box-shadow: 0px 12px 20px 0px rgba(0,0,0,0.1);
      border-radius: 16px;
      flex: 1;
      padding: 24px 48px;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
     .r-top{
      div{
        color: #222A42;
        font-size: 28px;
        strong{
          font-size: 48px;
        }
      }

     } 
     .r-bottom{
      display: flex;
      justify-content: space-between;
      strong{
        font-size: 40px!important;

      }
      .r-last{
        text-align: left;
        padding-right: 128px;
      }
     }
     .name{
      font-size: 28px;
      font-weight: 400;
      color: #999999;
      margin-top: -10px;
      display: block;
      }
    }
  }
}
.listmain li:nth-child(2) .listleft{
  background: linear-gradient(132deg, #7FD7D9 0%, #1FB5BA 100%);
}
.listmain li:nth-child(3) .listleft{
  background: linear-gradient(132deg, #9AB2FE 0%, #436FFF 100%);
}
.listmain li:nth-child(4) .listleft{
  background: linear-gradient(135deg, #08A6FF 0%, #0060FF 100%);
}
.listmain li:nth-child(5) .listleft{
  background: linear-gradient(132deg, #CBA2F4 0%, #9B60E1 100%);
}
</style>
